import { createRouter, createWebHistory } from 'vue-router'

import Login from '@/views/Login/index.vue'
import Layout from '@/views/Layout/index.vue'
import Home from '@/views/Home/index.vue'
import Category from '@/views/Category/index.vue'
import SubCategory from '@/views/SubCategory/index.vue'
import Detail from '@/views/Detail/index.vue'
import CartList from '@/views/CartList/index.vue'
import CheckOut from '@/views/CheckOut/index.vue'
import Pay from '@/views/Pay/index.vue'
import PayBack from '@/views/Pay/PayBack.vue'
import Member from '@/views/Member/index.vue'
import MemberInfo from '@/views/Member/components/MemberInfo.vue'
import MemberOrder from '@/views/Member/components/MemberOrder.vue'
import Search from '@/views/Search/index.vue'
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path:'/',
      component:Layout,
      children:[  //二级路由
        {
          path:'',
          component:Home
        },
        {
          path:'category/:id',
          component:Category
        },
        {
          path:'category/sub/:id',
          component:()=>('./views/SubCategory/index.vue')  //懒加载  导航栏下的二级栏目
          // component:SubCategory
        },
        {
          path:'search',
          component:()=>('./views/Search/index.vue')  //懒加载  搜索页面
          // component:Search
        },
        {
          path:'detail/:id',
          component:()=>('./views/Detail/index.vue')  //懒加载 商品详情页
          // component:Detail
        },
        {
          path:'cartlist',
          component:()=>('./views/Search/index.vue')  //懒加载 购物车列表
          // component:CartList
        },
        {
          path:'checkout',
          component:()=>('.views/CheckOut/index.vue')  //懒加载 订单提交
          // component:CheckOut
        },
        {
          path:'pay',
          component:()=>('./views/Pay/index.vue')  //懒加载组件 支付
          // component:Pay
        },
        {
          path: 'paycallback', // 注意路径，必须是paycallback
          component:()=>('./views/Pay/PayBack.vue')  //懒加载组件  完成支付
          // component: PayBack
        },
        {
          path: '/member',
          component: Member,
          children:[
            {
              path: '',
              component:()=>('./views/Member/components/MemberOrder.vue')  //懒加载组件  会员中心的个人信息
              // component: MemberInfo
            },
            {
              path: 'order',
              component:()=>('./views/Member/components/MemberOrder.vue')  //懒加载组件  会员中心的订单
              // component: MemberOrder
            }
          ]
        }
      ]
    },
    {
      path:'/login',
      component:Login
    }
  ],
  // 路由行为定制
  scrollBehavior(){
    return{
      top:0
    }
  }
})

export default router
